﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PNProject.EF;
using PNProject.Core;

namespace PNProject.Core.Converter
{
    public class XUserConverter
    {
        public static XUser ToXUser(XUserModel user)
        {
            XUser obj = new XUser();
            try
            {
                obj.UserID = Guid.Parse(user.UserID);
                obj.Username = user.Username;
                obj.Name = user.Name;
                obj.Avatar = user.Avatar;
                obj.Phone = user.Phone;
                obj.Birthday = user.Birthday;
                obj.Email = user.Email;
                obj.Address = user.Address;
                obj.Info = user.Info;
                return obj;
            }
            catch (Exception e)
            {
                return new XUser();
            }
        }

        public static XUser CopyXUser(XUser user)
        {
            XUser obj = new XUser();
            try
            {
                obj.UserID = user.UserID;
                obj.Username = user.Username;
                obj.Name = user.Name;
                obj.Avatar = user.Avatar;
                obj.Phone = user.Phone;
                obj.Birthday = user.Birthday;
                obj.Email = user.Email;
                obj.Address = user.Address;
                obj.Info = user.Info;
                obj.IsBlocked = user.IsBlocked;
                obj.Role = user.Role;
                return obj;
            }
            catch (Exception e)
            {
                return new XUser();
            }
        }

        public static XUserModel XUserTo(XUser user)
        {
            XUserModel obj = new XUserModel();
            obj.UserID = user.UserID.ToString();
            obj.Username = user.Username;
            obj.Name = user.Name;
            obj.Avatar = user.Avatar;
            obj.Phone = user.Phone;
            obj.Birthday = user.Birthday;
            obj.Email = user.Email;
            obj.Address = user.Address;
            obj.Info = user.Info;
            obj.IsBlocked = user.IsBlocked.HasValue ? user.IsBlocked.Value : true;
            obj.Role = user.Role;
            return obj;
        }
    }
}